package com.ac.api.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.base.helper.StringUtils;
import com.ac.api.base.dao.AcPageMapper;
import com.ac.api.base.entity.AcPage;
import com.ac.api.base.service.AcPageService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mzl
 * @since 2020-07-09
 */
@Service
public class AcPageServiceImpl extends ServiceImpl<AcPageMapper, AcPage> implements AcPageService {

    @Override
    public List<AcPage> list(AcPage example) {
        return this.list(buildWrapper(example));
    }

    @Override
    public IPage<AcPage> page(AcPage example, IPage page) {
        return this.page(page, buildWrapper(example));
    }

    private QueryWrapper<AcPage> buildWrapper(AcPage example) {
        QueryWrapper<AcPage> wrapper   = new QueryWrapper<>(example);
        String               grouptype = example.getGrouptype();
        wrapper.lambda()
                .eq(StringUtils.isNotEmpty(grouptype), AcPage::getGrouptype, grouptype)
                .orderByDesc(AcPage::getId);
        return wrapper;
    }

}
